﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DevFX.Infrastructure.ViewUtility.UC
{
    public partial class WaitCursorAnimation : UserControl
    {
        public WaitCursorAnimation()
        {
            InitializeComponent();
        }

        #region IsAnimating Dependency Property

        /// <summary>
        /// IsAnimating
        /// </summary>
        public bool IsAnimating
        {
            get { return (bool)GetValue(IsAnimatingProperty); }

            set { SetValue(IsAnimatingProperty, value); }
        }

        /// <summary>
        /// IsAnimating Dependency Property.
        /// </summary>
        public static readonly DependencyProperty IsAnimatingProperty = DependencyProperty.Register(
                                                                        "IsAnimating",
                                                                        typeof(bool),
                                                                        typeof(WaitCursorAnimation),
                                                                        new PropertyMetadata(false, IsAnimatingChangedCallback));


        private static void IsAnimatingChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            WaitCursorAnimation wca = obj as WaitCursorAnimation;

            if ((bool)e.NewValue == true)
            {
                wca.StartAnimation();
            }
            else
            {
                wca.StopAnimation();
            }
        }

        #endregion

        private void StartAnimation()
        {
            CircleAnimation.Begin();
            LayoutRoot.Visibility = Visibility.Visible;
        }

        private void StopAnimation()
        {
            CircleAnimation.Stop();
            LayoutRoot.Visibility = Visibility.Collapsed;
        }
    }
}
